package ro.peoplecentric.ctc.common.dao.impl;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Repository;
import ro.peoplecentric.ctc.common.dao.CategoryDao;
import ro.peoplecentric.ctc.common.entity.Category;

/**
 * {@link CategoryDao} implantation.
 *
 * @author pguzun
 */
@Repository
public class CategoryDaoImpl extends BaseDaoImpl implements CategoryDao {

    /**
     * @inheritDoc
     */
    @Override
    public List<Category> getAll() {
        final Criteria criteria = getSession().createCriteria(Category.class);
        criteria.addOrder(Order.asc("name"));
        return criteria.list();
    }

    /**
     * Gets default order by which fetching entity list must be sorted.
     *
     * @return Order
     */
    @Override
    protected Order getDefaultOrderBy() {
        return Order.asc("id");
    }
}
